package me.zhengjie.modules.lock.service.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.zelk.smartlock.common.constant.Constant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

@ApiModel("门锁设备指令列表信息")
@Data
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public class LockCmdListDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "指令Id", dataType = "Long")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long cmdId;

    @ApiModelProperty(value = "任务跟踪码", dataType = "Integer")
    private Integer trackId;

    @ApiModelProperty(value = "指令类型", dataType = "String")
    private String type;

    @ApiModelProperty(value = "指令状态", dataType = "String")
    private String status;

    @ApiModelProperty(value = "指令生效时间", dataType = "LocalDateTime")
    @JsonFormat(pattern = Constant.DATA_FORMAT, timezone = Constant.TIME_ZONE)
    private LocalDateTime startTime;

    @JsonFormat(pattern = Constant.DATA_FORMAT, timezone = Constant.TIME_ZONE)
    @ApiModelProperty(value = "指令失效时间", dataType = "LocalDateTime")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "关联钥匙Id", dataType = "Long", hidden = true)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long objId;

    @ApiModelProperty(value = "关联钥匙类型", dataType = "Long", hidden = true)
    private String objType;

    @ApiModelProperty(value = "关联钥匙Id字符串", dataType = "String")
    private String objIdStr;

    @ApiModelProperty(value = "商户Id", dataType = "String")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long partnerId;

    @ApiModelProperty(value = "商户名称", dataType = "String")
    private String partnerName;

    @JsonFormat(pattern = Constant.DATA_FORMAT, timezone = Constant.TIME_ZONE)
    @ApiModelProperty(value = "指令生成时间", dataType = "String")
    private LocalDateTime creatTime;

    public String getObjIdStr() {
        return Objects.nonNull(objId) ? objId + "(" + objType + ")" : null;
    }
}
